package com.ag.lzw.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import keeper.event.EventListener;

public class SendMsg implements EventListener{

	private String msg;

	public SendMsg(String msg) {
		this.msg = msg;
	}

	@Override
	public void process(HttpServletRequest request, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			if (msg != null) {  //向在线的客户端发送信息
				System.out.println("\n\t***Send msg to clients:"+msg);
				out.write(msg);   
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}
}
